<?php
/**
 *	@name		V认证
 *	@author		Jeffery
 *	@qq			1017756891
 *	@email		1017756891@qq.com
 *	@website	http://www.iweitao.net
**/

if(!defined('IN_AUTHENTICATE') || !defined('IN_DISCUZ')) {
	exit('Access Denied');
}

function loadlang_authenticate($lang){
	$return = array();
	$array=explode("\n",str_replace("\r","",$lang));
	foreach ($array as $v){
		$t = explode("=",$v);
		$t[0] = trim($t[0]);
		$return[$t[0]] = $t[1];
	}
	return $return;
}

function checkload_authenticate($lang) {
	global $_G;
	if(!isset($_G['cache']['plugin'])) {
		loadcache('plugin');
		return $_G['cache']['plugin']['authenticate']['lang'];
	} else {
		return $lang;
	}
}

function checkroot_authenticate() {
	global $_G;
	if(!isset($_G['cache']['plugin'])) {
		loadcache('plugin');
		$authenticate = $_G['cache']['plugin']['authenticate'];
		return $authenticate;
	}
	$authenticate = $_G['cache']['plugin']['authenticate'];
	return $authenticate;
}

function checkstatus_authenticate() {
	global $_G;
	global $open;
	global $lang;
	if(!$open) {
		showmessage($lang['error']);
	}
}

function checkgroup_authenticate() {
	global $_G;
	global $group;
	global $lang;
	if(!in_array($_G['groupid'],$group)) {
		showmessage($lang['check_group_error']);
	}
}

function checklogin_authenticate() {
	global $_G;
	if(empty($_G['uid'])) {
		return false;
	} else {
		return true;
	}
}

function GET_USER_V_INFO($uid = FALSE,$status = 0) {
	global $_G;
	global $lang;
	global $weitao_authenticate;
	if($uid == false) {
		$fetch = DB::query("SELECT * FROM `$weitao_authenticate` WHERE `status` = $status");
		if(mysql_fetch_array($fetch)) {
			$fetch = DB::query("SELECT * FROM `$weitao_authenticate` WHERE `status` = $status");
			while($query = mysql_fetch_array($fetch)) {
				$array[] = array(
					'uid' => $query['uid'],
					'username' => $query['username'],
					'name' => $query['name'],
					'phone' => $query['phone'],
					'email' => $query['email'],
					'QQ' => $query['QQ'],
					'idcode' => $query['idcode'],
					'index' => $query['toppath'],
					'bottom' => $query['bottompath'],
					'status' => $query['status'],
				);
			}
			return $array;
		} else {
			return false;
		}
	} else {
		$fetch = DB::query("SELECT * FROM `$weitao_authenticate` WHERE `uid` = '$uid'");
		if(mysql_fetch_array($fetch)) {
			$fetch = DB::query("SELECT * FROM `$weitao_authenticate` WHERE `uid` = '$uid'");
			while($query = mysql_fetch_array($fetch)) {
				$array = array(
					'uid' => $query['uid'],
					'username' => $query['username'],
					'name' => $query['name'],
					'phone' => $query['phone'],
					'email' => $query['email'],
					'QQ' => $query['QQ'],
					'idcode' => $query['idcode'],
					'index' => $query['toppath'],
					'bottom' => $query['bottompath'],
					'status' => $query['status'],
				);
			}
			return $array;
		} else {
			return false;
		}
	}
}

function changestatus_authenticate($op = 'deny', $uid) {
	global $_G;
	global $lang;
	global $weitao_authenticate;
	if($op == 'deny') {
		DB::query("DELETE FROM `$weitao_authenticate` WHERE `uid` = $uid");
	} else {
		DB::query("UPDATE `$weitao_authenticate` SET `status` = '1' WHERE `uid` = $uid");
	}
	return true;
}
?>